home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #1 / Amiga Plus CD - 1997 - No. 01.iso / pd / programmierung / proasm / routines / support.mac < prev    next >
Text File  |  1994-07-18  |  11KB  |  516 lines

  1.  
  2. ;---;  Support Macros  ;-------------------------------------------------------
  3. *
  4. *    ****    SUPPORT MACROS    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.22
  8. *    Last Revision    11.10.93
  9. *    Identifier    smc_defined
  10. *       Prefix        smc_    (Support Macros)
  11. *                 ¯       ¯ ¯
  12. *    Macros        print_        - smart print routine
  13. *            printtext_     - print a zero ended text
  14. *            printit_    - small interface for smc_PrintText
  15. *            printsubroutine_- smc_PrintText: (A0: text)
  16. *            clrEOF        - clear End Of Line (uses the print mac)
  17. *            DoRawFmt    - format a text
  18. *            PrintRaw    - format a text, then print it
  19. *            CheckBreak    - check for ^C/^D/^E/^F
  20. *            GetDosErr    - get Dos error text...
  21. *            smc_doserrors    - list of all Dos error texts
  22. *            OpenLib        - opens a library
  23. *            CloseLib    - close lib...
  24. *
  25. ;------------------------------------------------------------------------------
  26.  
  27. ;------------------
  28.     IFND    smc_defined
  29. smc_defined    =1
  30.  
  31.  
  32. ;------------------------------------------------------------------------------
  33. *
  34. * print_
  35. *
  36. * <text to be printed>,<DosBase>,<handle>
  37. *
  38. * default: <DosBase = DosBase(pc)>
  39. *
  40. * the <DosBase> and the <handle> may only be added the first time
  41. * you use this macro. if no outputhandle is defined, the routine will use
  42. * the dos output() function everytime to get the right handle.
  43. *
  44. * examples:    Print    "hallo welt",dosbasis(a5)
  45. *        Print    <"hallo welt",$a,"wie gehts?",$a>,,outuphandle(pc)
  46. *
  47. ;------------------------------------------------------------------------------
  48.  
  49. print_        MACRO
  50.         opt    sto,o+,q+,ow-        ;self optimising...
  51.         IFD    smc_Print
  52.         jsr    smc_Print
  53.         dc.b    \1,0
  54.         even
  55.         ELSE
  56.         bsr    ..smc_Print\#
  57.         dc.b    \1,0
  58.         even
  59.         bra    ..smc_afterPrint\#
  60.  
  61. ..smc_Print\#:
  62. smc_Print    EQU    ..smc_Print\#
  63.  
  64.         IFD    smc_PrintText
  65.         movem.l d0-a6,-(a7)
  66.         move.l  60(a7),a0        ;take text pointer
  67.         jsr    smc_PrintText        
  68. ..countloop\#:    tst.b   (a0)+            ;search end of string
  69.         bne.s   ..countloop\#
  70.         move.l  a0,d1
  71.         ELSE
  72.         movem.l d0-a6,-(a7)
  73.         move.l  60(a7),d2        ;take text pointer
  74.         move.l  d2,a3
  75. ..countloop\#:    tst.b   (a3)+            ;search end of string
  76.         bne.s   ..countloop\#
  77.         move.l  a3,d3
  78.         subq.l  #1,d3
  79.         sub.l   d2,d3            ;length
  80.         beq.s   ..nothingtowrite\#
  81.         IFC    '\2',''
  82.         move.l  DosBase(pc),a6
  83.         ELSE
  84.         move.l  \2,a6
  85.         ENDC
  86.         IFC    '\3',''
  87.         jsr    -60(a6)            ;output()
  88.         move.l    d0,d1
  89.         beq.s    ..nothingtowrite\#
  90.         ELSE
  91.         move.l  \3,d1
  92.         ENDC
  93.         jsr     -48(a6)            ;write()
  94. ..nothingtowrite\#:
  95.         move.l  a3,d1
  96.         ENDC
  97.         addq.l  #1,d1
  98.         and.b   #$fe,d1
  99.         move.l  d1,60(a7)        ;new return address
  100.         movem.l (a7)+,d0-a6
  101.         rts
  102. ..smc_afterPrint\#:
  103.         ENDC
  104.         opt    rcl
  105.         ENDM
  106.  
  107.  
  108. ;------------------------------------------------------------------------------
  109. *
  110. * Clear EndOfLine
  111. *
  112. ;------------------------------------------------------------------------------
  113.  
  114. clrEOF:        MACRO
  115.         print    <$9b,$4b>
  116.         ENDM
  117.  
  118.  
  119. ;------------------------------------------------------------------------------
  120. *
  121. * printtext_
  122. *
  123. * <textpointer>,<DosBase>,<handle>[,bra]
  124. *
  125. * default: <textpointer = a0>,<DosBase = DosBase(pc)>
  126. *
  127. * the <DosBase> and the <handle> may only be added the first time
  128. * you use this macro. if no outputhandle is defined, the routine will use
  129. * the dos output() function everytime to get the right handle.
  130. * the optional 'bra' parameter indicates the macro that the user want to
  131. * use the printtext routine via bra.
  132. *
  133. * example:    printtext_    ,dosybasy(a1),handely(a4)  ;define base/handle
  134. *        printtext_                   ;simply print text
  135. *
  136. ;------------------------------------------------------------------------------
  137.  
  138. printtext_    MACRO
  139.         opt    sto,o+,q+,ow-        ;self optimising...
  140.         IFD    smc_PrintText
  141.         IFNC    '\1',''
  142.         lea    \1,a0
  143.         ENDC
  144.         IFNC    '\4','bra'
  145.         jsr    smc_PrintText
  146.         ELSE
  147.         jmp    smc_PrintText
  148.         ENDC
  149.         ELSE
  150.         IFNC    '\1',''
  151.         lea    \1,a0
  152.         ENDC
  153.         IFNC    '\4','bra'
  154.         bsr.s   smc_PrintText
  155.         bra    smc_afterPrintText\#
  156.         ELSE
  157. ;        bra.s   smc_PrintText    ;not needed, print code follows...
  158.         ENDC
  159.  
  160.         printsubroutine_ \2,\3
  161. smc_afterPrintText\#:    EQU    *
  162.         ENDC
  163.         opt    rcl
  164.         ENDM
  165.  
  166.  
  167. ;------------------------------------------------------------------------------
  168. *
  169. * printit_ <kind>
  170. *
  171. * A0: text to be printed
  172. *
  173. * <kind is either 'bra', 'jm', 'bsr', 'jsr' (default: 'jsr')>
  174. *
  175. * This macro is just a small interface for the printtext_/printsubroutine_
  176. * macros.
  177. *
  178. ;------------------------------------------------------------------------------
  179.  
  180. printit_    MACRO
  181.         opt    sto
  182.         opt    o+,ow-
  183.         IFC    '\1','bra'
  184.         bra    smc_PrintText
  185.         ENDC
  186.         IFC    '\1','jmp'
  187.         jmp    smc_PrintText
  188.         ENDC
  189.         IFC    '\1','bsr'
  190.         bsr    smc_PrintText
  191.         ENDC
  192.         IFC    '\1','jsr'
  193.         jsr    smc_PrintText
  194.         ENDC
  195.         IFC    '\1',''
  196.         jsr    smc_PrintText
  197.         ENDC
  198.         ENDM
  199.  
  200.  
  201. ;------------------------------------------------------------------------------
  202. *
  203. * Print Subroutine...
  204. *
  205. * <DosBase>,<outputhd>
  206. *
  207. * default: <DosBase(pc)>,<jsr _LVOOutput(DosBase)>
  208. *
  209. * A0: text to print
  210. *
  211. * (for details see the PrintText macro)
  212. *
  213. ;------------------------------------------------------------------------------
  214.  
  215. printsubroutine_    MACRO
  216.  
  217. smc_PrintText:    EQU    *
  218.         movem.l d0-a6,-(a7)        ;a0: textpointer
  219.         move.l  a0,d2
  220. .countloop\#:    tst.b   (a0)+            ;search end of string
  221.         bne.s   .countloop\#
  222.         move.l  a0,d3
  223.         subq.l  #1,d3
  224.         sub.l   d2,d3            ;length
  225.         beq.s   .nothingtowrite\#
  226.         IFC    '\1',''
  227.         move.l  DosBase(pc),a6
  228.         ELSE
  229.         move.l  \1,a6
  230.         ENDC
  231.         IFC    '\2',''
  232.         jsr    -60(a6)            ;output()
  233.         move.l    d0,d1
  234.         beq.s    .nothingtowrite\#
  235.         ELSE
  236.         move.l  \2,d1
  237.         ENDC
  238.         jsr     -48(a6)            ;write()
  239. .nothingtowrite\#:
  240.         movem.l (a7)+,d0-a6
  241.         rts
  242.         ENDM
  243.  
  244.  
  245. ;------------------------------------------------------------------------------
  246. *
  247. * DoRawFmt
  248. *
  249. * <unformated text>,<rawlist>,<targetbuffer>
  250. *
  251. * => d0: length of string
  252. * => a0: target buffer
  253. *
  254. ;------------------------------------------------------------------------------
  255.  
  256. DoRawFmt:    MACRO
  257.         opt    sto,o+,q+,ow-
  258.         IFD    smc_DoRawFmt
  259.         move.l    \1,a0            ;unformated text
  260.         move.l    \2,a1            ;rawlist
  261.         move.l    \3,a3            ;target buffer
  262.         jsr    smc_DoRawFmt
  263.         ELSE
  264.         move.l    \1,a0            ;unformated text
  265.         move.l    \2,a1            ;rawlist
  266.         move.l    \3,a3            ;target buffer
  267.         pea    smc_afterDoRawFmt(pc)
  268.  
  269. smc_DoRawFmt:    movem.l    d1-d7/a2/a4-a6,-(a7)
  270.         move.l    a3,d3
  271.         lea    .setin(pc),a2
  272.         move.l    4.w,a6
  273.         jsr    -522(a6)        ;RawDoFmt()
  274.         move.l    d3,a0
  275.         move.l    d3,a2
  276. .loop:        tst.b    (a2)+
  277.         bne.s    .loop
  278.         sub.l    d3,a2
  279.         move.l    a2,d0            ;length
  280.         movem.l    (a7)+,d1-d7/a2/a4-a6
  281.         rts
  282.  
  283. .setin:        move.b    d0,(a3)+
  284.         rts
  285. smc_afterDoRawFmt:
  286.         ENDC
  287.         opt    rcl
  288.         ENDM
  289.  
  290.  
  291. ;------------------------------------------------------------------------------
  292. *
  293. * PrintRaw
  294. *
  295. * <unformated text>,<rawlist>,<targetbuffer>,<DosBase>,<outputhd>
  296. *
  297. * default: <DosBase = DosBase(pc)>
  298. *
  299. * (see the Print/PrintText macro for information)
  300. ;------------------------------------------------------------------------------
  301.  
  302. PrintRaw:    MACRO
  303.         DoRawFmt    \1,\2,\3
  304.         PrintText    ,\4,\5
  305.         ENDM
  306.  
  307.  
  308. ;------------------------------------------------------------------------------
  309. *
  310. * CheckBreak
  311. *
  312. * <kind of break: c/d/e/f>
  313. *
  314. * default:    <c>
  315. *
  316. * => d0:16: 0: no break  -: break occured
  317. *
  318. ;------------------------------------------------------------------------------
  319.  
  320. CheckBreak:    MACRO
  321.         movem.l    d1-a6,-(a7)
  322.         move.l    4.w,a6
  323.         move.l    276(a6),a1        ;*thistask
  324.         moveq    #0,d0
  325.         jsr    -324(a6)        ;signal()
  326.         IFC    '\1',''
  327.         and.l    #$1000,d0
  328.         ENDC
  329.         IFC    '\1','c'
  330.         and.l    #$1000,d0
  331.         ENDC
  332.         IFC    '\1','d'
  333.         and.l    #$2000,d0
  334.         ENDC
  335.         IFC    '\1','e'
  336.         and.l    #$4000,d0
  337.         ENDC
  338.         IFC    '\1','f'
  339.         and.l    #$8000,d0
  340.         ENDC
  341.         movem.l    (a7)+,d1-a6
  342.         ENDM
  343.  
  344.  
  345. ;------------------------------------------------------------------------------
  346. *
  347. * GetDosErr()
  348. *
  349. * <error number>
  350. *
  351. * => d0: zero ended string or zero if no string was found
  352. *
  353. * default:    value already in d0
  354. *
  355. ;------------------------------------------------------------------------------
  356.  
  357. GetDosErr:    MACRO
  358.         IFNC    '\1',''
  359.         move.l    \1,d0
  360.         ENDC
  361.         move.l    a0,-(a7)        
  362.         lea    smc_errortexts(pc),a0
  363. .smc_tst\@:    cmp.b    (a0)+,d0
  364.         beq    smc_gde\@
  365. .smc_loop\@:    tst.b    (a0)+
  366.         bne.s    .smc_loop\@
  367.         tst.b    (a0)            ;end reached?
  368.         bne.s    .smc_tst\@
  369.         moveq    #0,d0            ;text not found...
  370.         bra    smc_out\@
  371.  
  372.         IFND    smc_doserrortexts
  373.         smc_doserrors
  374.         endif
  375.  
  376. smc_gde\@:    move.l    a0,d0
  377. smc_out\@:    move.l    (a7)+,a0
  378.         ENDM
  379.  
  380.  
  381. ;------------------------------------------------------------------------------
  382. *
  383. * smc_doserrors
  384. *
  385. * list of dos error texts...
  386. *
  387. ;------------------------------------------------------------------------------
  388.  
  389. smc_doserrors:    MACRO
  390. smc_doserrortexts:
  391.         dc.b    103,"no free store",0
  392.         dc.b    105,"task table full",0
  393.         dc.b    114,"bad template",0
  394.         dc.b    115,"bad number",0
  395.         dc.b    116,"required argument missing",0
  396.         dc.b    117,"key needs argument",0
  397.         dc.b    118,"too many arguments",0
  398.         dc.b    119,"unmatched quotes",0
  399.         dc.b    120,"line too long",0
  400.         dc.b    121,"file not object",0
  401.         dc.b    122,"invalid resident library",0
  402.         dc.b    201,"no default directory",0
  403.         dc.b    202,"object in use",0
  404.         dc.b    203,"object exists",0
  405.         dc.b    204,"directory not found",0
  406.         dc.b    205,"object not found",0
  407.         dc.b    206,"bad stream name",0
  408.         dc.b    207,"object too large",0
  409.         dc.b    209,"action not known",0
  410.         dc.b    210,"invalid component name",0
  411.         dc.b    211,"invalid lock",0
  412.         dc.b    212,"object not of required type",0
  413.         dc.b    213,"disk not validated",0
  414.         dc.b    214,"disk write protected",0
  415.         dc.b    215,"rename across devices",0
  416.         dc.b    216,"directory not empty",0
  417.         dc.b    217,"too many levels",0
  418.         dc.b    218,"device not mounted",0
  419.         dc.b    219,"seek error",0
  420.         dc.b    220,"comment too big",0
  421.         dc.b    221,"disk full",0
  422.         dc.b    222,"delete protected",0
  423.         dc.b    223,"file is write protected",0
  424.         dc.b    224,"file is read protected",0
  425.         dc.b    225,"not a DOS disk",0
  426.         dc.b    226,"no disk in drive",0
  427.         dc.b    232,"no more entries",0
  428.         dc.b    233,"object is soft link",0    ;added for 1.4
  429.         dc.b    234,"object linked",0        ;"
  430.         dc.b    235,"bad hunk",0        ;"
  431.         dc.b    236,"not implemented",0        ;"
  432.         dc.b    240,"record not locked",0    ;"
  433.         dc.b    241,"lock collision",0        ;"
  434.         dc.b    242,"lock timeout",0        ;"
  435.         dc.b    243,"unlock error",0        ;"
  436.         dc.b    0                ;end of list
  437.         even
  438.         ENDM
  439.  
  440.  
  441. ;------------------------------------------------------------------------------
  442. *
  443. * OpenLib    - Library Help Macro
  444. * CloseLib
  445. *
  446. * OpenLib    <library>,<base>,<version>
  447. * Default    <>,d0,#0
  448. *
  449. * CloseLib    <base>
  450. *
  451. ;------------------------------------------------------------------------------
  452.  
  453. OpenLib:    MACRO
  454.         OPT    sto,o+,ow-,q+
  455.         IFC    '\1','dos'
  456.         lea    \dosname(pc),a1
  457.         ELSE
  458.         IFC    '\1','intuition'
  459.         lea    \intname(pc),a1
  460.         ELSE
  461.         IFC    '\1','graphics'
  462.         lea    \gfxname(pc),a1
  463.         ELSE
  464.         FAIL    library not supported
  465.         ENDC
  466.         ENDC
  467.         ENDC
  468.         IFC    '\3',''
  469.         moveq    #0,d0
  470.         ELSE
  471.         move.l    #\3,d0
  472.         ENDC
  473.         IFD    smc_OpenLib
  474.         jsr    smc_OpenLib
  475.         ELSE
  476.         pea    smc_OpenLibEnd(pc)
  477. smc_OpenLib:    movem.l    d1-a6,-(a7)
  478.         move.l    4.w,a6
  479.         jsr    -552(a6)        ;OpenLibrary()
  480.         movem.l    d1-a6,-(a7)
  481.         rts
  482. smc_OpenLibEnd:
  483.         ENDC
  484.         IFNC    '\2',''
  485.         move.l    d0,\2
  486.         ENDC
  487.         ENDM
  488.  
  489.  
  490. ;------------------------------------------------
  491. CloseLib:    MACRO
  492.         IFC    '\1',''
  493.         FAIL    CloseLib: no base given
  494.         ENDC
  495.         IFD    smc_CloseLib
  496.         jsr    smc_CloseLib
  497.         ELSE
  498.         move.l    \1,a1
  499.         pea    smc_CloseLibEnd(pc)
  500. smc_CloseLib:    movem.l    d0-a6,-(a7)
  501.         move.l    4.w,a6
  502.         jsr    -414(a6)        ;CloseLibrary()
  503.         movem.l    (a7)+,d0-a6
  504.         rts
  505. smc_CloseLibEnd:
  506.         ENDC
  507.         ENDM
  508.  
  509. ;------------------------------------------------------------------------------
  510.  
  511.     endif
  512.  
  513.  end
  514.  
  515.